import numpy as np
from sklearn.cluster import KMeans
import matplotlib.pyplot as plt

# 生成示例数据
X = np.array([[1], [2], [3], [4], [5]])

# 创建K-Means模型并拟合数据
model = KMeans(n_clusters=2)
model.fit(X)

# 预测
y_pred = model.predict(X)

# 绘制结果
plt.scatter(X, np.zeros_like(X), c=y_pred, cmap='viridis')
plt.title("K-Means Clustering Example")
plt.xlabel("X")
plt.show()